﻿using Caliburn.Micro;
using System.Windows.Input;
using System.Windows;
using ThunderboltInterfaceSharp.Views;

namespace ThunderboltInterfaceSharp.ViewModels;

public class FloatingViewModel:Screen
{
	private Point _pressedPosition;
	private bool _isDragMoved = false;
	private FloatingView _floatingView;
	public FloatingViewModel()
	{

	}
	//不要用private方法
	public void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
	{
		_pressedPosition = e.GetPosition(sender as ThunderMainView);
	}
	public void MouseMove(object sender, MouseEventArgs e)
	{
		//前端传入参数view而不是this
		var view = sender as FloatingView;
		if (Mouse.LeftButton == MouseButtonState.Pressed && _pressedPosition != e.GetPosition(view))
		{
			_isDragMoved = true;
			view?.DragMove();
		}
	}
	public void MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
	{
		if (_isDragMoved)
		{
			_isDragMoved = false;
			e.Handled = true;
		}
	}

	protected override void OnViewLoaded(object view)
	{
		_floatingView = view as FloatingView;
	}
}